#include "bullet.h"

#include <iostream>

using namespace std;

Bullet::~Bullet()
{
}
Bullet::Bullet(float ra) : BallObject(Ball(0.05f))
{
    Camera &camera = Camera::getinstance();
    ball.setColor(0.5f, 0.5f, 0.5f); //颜色
    pos = camera.Position();         //出发位置
    front = camera.front();
}

void Bullet::draw(Shader shader) //绘制
{
    ball.draw(shader, pos.x, pos.y, pos.z);
}

void Bullet::update(float dt) //销毁
{
    float speed = 2; //以2单位时速移动
    pos = pos + dt * speed * front;

    set<BlockObject *> list = getCollidedBlocks(*this); //寻找碰撞的球
    for (set<BlockObject *>::iterator i = list.begin(); i != list.end(); i++)
    {
        BlockObject *blk = *i;
        blk->droped = true;
    }
    if (!list.empty())
    {
        droped = true;
    }
    if (pos.z < -10)
        droped = true;
}
